package net.fruit.mq.client.bean;

import java.util.Properties;

import net.fruit.mq.client.MQFactory;
import net.fruit.mq.client.Message;
import net.fruit.mq.client.Producer;
import net.fruit.mq.client.SendCallback;
import net.fruit.mq.client.SendResult;
import net.fruit.mq.client.exception.LMQClientException;


public class ProducerBean implements Producer {
    private Properties properties;

    private Producer producer;


    @Override
    public void start() {
        if (null == this.properties) {
            throw new LMQClientException("properties not set");
        }

        this.producer = MQFactory.createProducer(this.properties);
        this.producer.start();
    }


    @Override
    public void shutdown() {
        if (this.producer != null) {
            this.producer.shutdown();
        }
    }


    @Override
    public SendResult send(Message message) {
        return this.producer.send(message);
    }


    @Override
    public void sendOneway(Message message) {
        this.producer.sendOneway(message);
    }

    @Override
    public void sendAsync(Message message, SendCallback sendCallback) {
        this.producer.sendAsync(message, sendCallback);
    }

    public Properties getProperties() {
        return properties;
    }


    public void setProperties(Properties properties) {
        this.properties = properties;
    }

    @Override
    public boolean isStarted() {
        return this.producer.isStarted();
    }

    @Override
    public boolean isClosed() {
        return this.producer.isClosed();
    }
}

